import axios from 'axios'

// import {
//   Loading
// } from 'element-ui'
// const loadingInstance = Loading.service({
//   lock: true,
//   text: 'Loading',
//   spinner: 'el-icon-loading',
//   background: 'rgba(0, 0, 0, 0.7)'
// })
// let requestNum = 0

var http = axios.create({
  baseURL: 'http://192.168.0.222:3001'

  // 测试接口地址
  // baseURL:'https://www.fastmock.site/mock/ad76771c2613290aa376970c89812995/movie'
})
// 请求拦截器，设置请求头content-type为JSON格式
http.interceptors.request.use(config => {
  // requestNum++
  // console.log(config);
  if(config.url === '/user/upload'){
    config.headers = Object.assign(config.headers, {
      'Content-Type': 'text/plain; charset=utf-8',
      'Authorization': `Bearer ${localStorage.getItem('token')}`
    })
  }else{
    config.headers = Object.assign(config.headers, {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${localStorage.getItem('token')}`
  })
  }
  
  return config
})
// 响应拦截器
http.interceptors.response.use(res => {
  // requestNum--
  // if (!requestNum) {
  //   loadingInstance.close()
  // }
  // console.log(res);
  return res.data
})

export {
  http
}
